﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 造物的属性
/// </summary>
public class CreatureData : MonoBehaviour
{

    public MonoBehaviour Component // 造物的管理器 TODO 想办法整成只读的
    { get; set; }
    /// <summary>
    /// 当前所在骰子
    /// </summary>
    public DiceData CoorDinate { get; set; }

    public Vector3 Towards // 朝向
    {
        //get { return new Vector3Int((int)transform.forward.x, (int)transform.forward.y, (int)transform.forward.z); }
        get { return transform.forward; }
    }

    public int hp = -1;
    /// <summary>
    /// 血量
    /// </summary>
    public int HP
    {
        get
        {
            if (hp >= 0)
            {
                return hp;
            }
            else
            {
                Debug.LogWarning("hp is not Initiate or target is DIED!!!" + gameObject.name);
                return 0;
            }
        }
        set { hp = value; }
    }

    public int atk = -1;
    /// <summary>
    /// 攻击力
    /// </summary>
    public int ATK
    {
        get
        {
            if (atk >= 0)
            {
                return atk;
            }
            else
            {
                Debug.LogError("atk is not Initiate!");
                return 0;
            }
        }
        set { atk = value; }
    }

    public int def = -1;


    /// <summary>
    /// 防御力
    /// </summary>
    public int DEF
    {
        get
        {
            if (def >= 0)
            {
                return def;
            }
            else
            {
                Debug.LogError("def is not Initiate!");
                return 0;
            }
        }
        set { def = value; }
    }

    /// <summary>
    /// 刷新坐标
    /// </summary>
    /// <returns>是否成功</returns>
    public bool FlushCoordinate(DiceData to = null)
    {
        if (to != null)
        {
            CoorDinate = to;
            //Debug.Log("刷新坐标" + gameObject.name);
            return true;
        }
        if (tag == "Player")
        {
            GameObject dice;
            if (transform.parent.parent)
            {
                dice = transform.parent.parent.parent.gameObject;
                if (dice.tag == "Dice")
                {
                    DiceData diceData = dice.GetComponent<DiceController>().Data;
                    CoorDinate = diceData;
                    //Debug.Log("刷新玩家坐标");
                    return true;
                }
            }
        }
        else
        {
            GameObject dice;
            if (transform.parent)
            {
                dice = transform.parent.parent.gameObject;
                if (dice.GetComponent<DiceController>())
                {
                    CoorDinate = dice.GetComponent<DiceController>().Data;
                    //Debug.Log("刷新敌人坐标");
                    return true;
                }
            }
        }
        return false;
    }
}
/*
 * 注意！ 定义class中的任意一种数值
 * 初始值应为不可能的值
 * 然后在get时进行判断是否赋值过（赋值过则为可能的值）
 * 未赋值过则返回某个特定值并报错
 * 来保证即使忘记初始化，游行进程依然可以进行，但是可以发现出现了问题
 */
